package cbbx_sm.decision_maker.search;

import java.io.Serializable;
import java.util.Hashtable;

/**
 * @author ronenvaisenberg
 * 
 * This class supports the dynamic generation of schedule options.
 *
 */
public class Schedules implements Serializable {
	public static final String UP = "UP";
	private String[] schedulesAvailable = {"C0","C1","C2","C3", UP};
	private Hashtable<String, Integer> scheduleIdMap = null;
	
//	static {
//		populateScheduleIdMap();
//	}
	
	public Schedules(String[] schedules) throws Exception{
		if (schedules[schedules.length-1]!=UP){
			throw new Exception("Last state must be UP");
		}
		
		schedulesAvailable = schedules;
		populateScheduleIdMap();
		
	}
	
	private void populateScheduleIdMap(){
		scheduleIdMap = new Hashtable<String, Integer>();
		for (int i=0; i<schedulesAvailable.length; i++){
			scheduleIdMap.put(schedulesAvailable[i], i);
		}
	}
	public Schedules(int numberOfZoomLocations){
		schedulesAvailable = new String[numberOfZoomLocations+1];
		scheduleIdMap.clear();
		int i;
		for (i=0; i<numberOfZoomLocations; i++){
			schedulesAvailable[i] = "C"+i;
		}
		schedulesAvailable[i] = UP;
		
		for (i=0; i<schedulesAvailable.length; i++){
			scheduleIdMap.put(schedulesAvailable[i], i);
		}
	}
	
	public String[] getSchedules(){
		return schedulesAvailable;
	}
	
	public int scheduleToCameraId(String schedule){
		return scheduleIdMap.get(schedule);
	}
}
